package com.csu.common.handler;

import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * @项目名称：express
 * @类名称：BeanConfiguration
 * @类描述：
 * @创建人：Tangc
 * @创建时间：2017年10月17日 下午5:52:58
 * @company:
 */
// @Configuration
public class BeanConfiguration
{

    // @Bean
    public CorsFilter corsFilter()
    {
        final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
        final CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsFilter(urlBasedCorsConfigurationSource);
    }

    /*
     * @Bean public WebMvcConfigurer corsConfigurer() { return new
     * WebMvcConfigurerAdapter() {
     * 
     * @Override public void addCorsMappings(CorsRegistry registry) {
     * registry.addMapping("/*").allowedOrigins("*"); } }; }
     */

}
